package com.qianniu.napi.admin.entity;

import com.baomidou.mybatisplus.enums.IdType;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import java.io.Serializable;

import static java.math.BigDecimal.ROUND_HALF_DOWN;

/**
 * <p>
 * 发起砍价活动
 * </p>
 *
 * @author chenxuebin
 * @since 2018-07-14
 */
@TableName("t_cutprice_open")
public class CutpriceOpen extends Model<CutpriceOpen> {

    private static final long serialVersionUID = 1L;

	@TableId(value="id", type= IdType.AUTO)
	private Long id;
	
    /**
     * 砍价活动id
     */
	private Long cid;

    /**
     * 商品id
     */
	private Long gid;
	private Long oid;

    /**
     * 商品名
     */
	private String gname;

    /**
     * 商品图
     */
	private String pic;
	private String nickname;
	private String avatarpic;

	@TableField(exist = false)
	private String statusStr;

    /**
     * 限量几份商品
     */
	private Integer number;

    /**
     * 最低价
     */
	private BigDecimal minprice;

	@TableField(exist = false)
	private BigDecimal helpPrice;

    /**
     * 原价
     */
	private BigDecimal price;

    /**
     * 当前价格
     */
	private BigDecimal curprice;

    /**
     * 总砍价
     */
	@TableField("totalcut_price")
	private BigDecimal totalcutPrice;

    /**
     * 业务状态@1：未开始；2：进行中；3：砍价成功；4：砍价失败；5：活动结束
     */
	private Integer status;

	@TableField(exist = false)
	private int cutPercent;

	@TableField(exist = false)
	private BigDecimal cutprice;

	@TableField(exist = false)
	private boolean hasCut;

	@TableField(exist = false)
	private boolean hasOrder;

	@TableField(exist = false)
	private String info;

    /**
     * 开始时间
     */
	private Date starttime;
    /**
     * 结束时间
     */
	private Date endtime;

    /**
     * 发起砍价活动人id，个人或者商家创建
     */
	private Long uid;
	private Long mid;
	private Long sid;

	private Long mpid;
	private Long modifier;

	private Date createtime;
	private Date modifytime;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCid() {
		return cid;
	}

	public void setCid(Long cid) {
		this.cid = cid;
	}

	public Long getGid() {
		return gid;
	}

	public void setGid(Long gid) {
		this.gid = gid;
	}

	public String getGname() {
		return gname;
	}

	public void setGname(String gname) {
		this.gname = gname;
	}

	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}

	public Integer getNumber() {
		return number;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

//	public boolean isHasCut() {
//		return curprice.doubleValue()> minprice.doubleValue()? true:false;
//	}

	public Long getMid() {
		return mid;
	}

	public void setMid(Long mid) {
		this.mid = mid;
	}

	public Long getMpid() {
		return mpid;
	}

	public void setMpid(Long mpid) {
		this.mpid = mpid;
	}

	public BigDecimal getHelpPrice() {
		return helpPrice;
	}

	public void setHelpPrice(BigDecimal helpPrice) {
		this.helpPrice = helpPrice;
	}

	public boolean isHasOrder() {
		return hasOrder;
	}

	public void setHasOrder(boolean hasOrder) {
		this.hasOrder = hasOrder;
	}

	public void setHasCut(boolean hasCut) {
		this.hasCut = hasCut;
	}

	public boolean isHasCut() {
		return hasCut;
	}

	public BigDecimal getMinprice() {
		return minprice;
	}

	public void setMinprice(BigDecimal minprice) {
		this.minprice = minprice;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public BigDecimal getCurprice() {
		return curprice;
	}

	public void setCurprice(BigDecimal curprice) {
		this.curprice = curprice;
	}

	public int getCutPercent() {
		BigDecimal hudrend = new BigDecimal(100);
		return totalcutPrice.divide(price.subtract(minprice),2,ROUND_HALF_DOWN).multiply(hudrend).intValue();
//		return curprice.divide(totalcutPrice).multiply(hudrend).intValue();
	}

	public BigDecimal getTotalcutPrice() {
		return totalcutPrice;
	}

	public void setTotalcutPrice(BigDecimal totalcutPrice) {
		this.totalcutPrice = totalcutPrice;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public Date getStarttime() {
		return starttime;
	}

	public void setStarttime(Date starttime) {
		this.starttime = starttime;
	}

	public Date getEndtime() {
		return endtime;
	}

	public void setEndtime(Date endtime) {
		this.endtime = endtime;
	}

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Date getModifytime() {
		return modifytime;
	}

	public void setModifytime(Date modifytime) {
		this.modifytime = modifytime;
	}

	public Long getModifier() {
		return modifier;
	}

	public void setModifier(Long modifier) {
		this.modifier = modifier;
	}

	public Long getOid() {
		return oid;
	}

	public void setOid(Long oid) {
		this.oid = oid;
	}

	public String getStatusStr() {
		if(status==1)statusStr="未开始";
		if(status==2)statusStr="进行中";
		if(status==3)statusStr="砍价成功";
		if(status==4)statusStr="砍价失败";
		if(status==5)statusStr="砍价结束";
		return statusStr;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getAvatarpic() {
		return avatarpic;
	}

	public void setAvatarpic(String avatarpic) {
		this.avatarpic = avatarpic;
	}

	public Long getSid() {
		return sid;
	}

	public void setSid(Long sid) {
		this.sid = sid;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

	@Override
	public String toString() {
		return "CutpriceOpen{" +
			"id=" + id +
			", cid=" + cid +
			", gid=" + gid +
			", gname=" + gname +
			", pic=" + pic +
			", number=" + number +
			", minprice=" + minprice +
			", price=" + price +
			", curprice=" + curprice +
			", totalcutPrice=" + totalcutPrice +
			", status=" + status +
			", starttime=" + starttime +
			", endtime=" + endtime +
			", uid=" + uid +
			", createtime=" + createtime +
			", modifytime=" + modifytime +
			"}";
	}
}
